package com.ruoyi.common.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * <p>
 * 订单表，存储用户参与霸王餐活动的订单信息
 * </p>
 *
 * @author jiabao
 * @since 2025-06-25
 */
@Getter
@Setter
@ToString
@Builder
@TableName("business_orders")
@ApiModel(value = "Orders对象", description = "订单表，存储用户参与霸王餐活动的订单信息")
public class Orders implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 订单ID，主键自增
     */
    @ApiModelProperty("订单ID，主键自增")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 订单编号(业务唯一，用于订单查询)
     */
    @TableField("order_no")
    @ApiModelProperty("订单编号(业务唯一，用于订单查询)")
    private String orderNo;

    /**
     * 关联business_users表的用户ID
     */
    @TableField("user_id")
    @ApiModelProperty("关联business_users表的用户ID")
    private Long userId;

    /**
     * 关联business_activity表的活动ID
     */
    @TableField("activity_id")
    @ApiModelProperty("关联business_activity表的活动ID")
    private Long activityId;

    /**
     * 关联business_merchants表的商家ID
     */
    @TableField("merchant_id")
    @ApiModelProperty("关联business_merchants表的商家ID")
    private Long merchantId;

    /**
     * 订单实际支付金额(单位：元)
     */
    @TableField("amount")
    @ApiModelProperty("订单实际支付金额(单位：元)")
    private BigDecimal amount;


    /**
     * 订单实际支付金额(单位：元)
     */
    @TableField("demand_amount")
    @ApiModelProperty("订单要求支付金额(单位：元)")
    private BigDecimal demandAmount;

    /**
     * 订单状态：0-待支付 1-已支付 2-已完成 3-已退款 4-已取消
     */
    @TableField("status")
    @ApiModelProperty("订单状态：1 正常 0删除")
    private Integer status;

    /**
     * 支付成功时间(用于统计和分析)
     */
    @TableField("payment_time")
    @ApiModelProperty("支付成功时间(用于统计和分析)")
    private LocalDateTime paymentTime;

    /**
     * 订单完成时间(用户消费完成时间)
     */
    @TableField("complete_time")
    @ApiModelProperty("订单完成时间(用户消费完成时间)")
    private LocalDateTime completeTime;

    /**
     * 微信支付交易单号(用于退款和对账)
     */
    @TableField("wx_transaction_id")
    @ApiModelProperty("微信支付交易单号(用于退款和对账)")
    private String wxTransactionId;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    @TableField("created_at")
    private LocalDateTime createdAt;

    /**
     * 最后更新时间
     */
    @TableField("updated_at")
    @ApiModelProperty("最后更新时间")
    private LocalDateTime updatedAt;





    @TableField("whether_comment")
    @ApiModelProperty("是否需要评论")
    private String whetherComment;


    @TableField("reject_reason")
    @ApiModelProperty("驳回原因")
    private String rejectReason;


    @Getter
    public enum WHETHER_COMMENT {
        NO_NEED_COMMENT("无需评价", "NO_NEED_COMMENT"),
        NEED_COMMENT("需要评价", "NEED_COMMENT");

        private final String desc;
        private final String value;

        WHETHER_COMMENT(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        // 返回随机枚举值的value字符串
        public static String getRandom() {
            WHETHER_COMMENT[] values = values();
            return values[new Random().nextInt(values.length)].value;
        }

        // 返回随机枚举实例
        public static WHETHER_COMMENT random() {
            WHETHER_COMMENT[] values = values();
            return values[new Random().nextInt(values.length)];
        }

        // 通过value获取枚举实例
        public static WHETHER_COMMENT fromValue(String value) {
            for (WHETHER_COMMENT type : values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("未知的状态类型: " + value);
        }
    }


    @TableField("current_status")
    @ApiModelProperty("订单当前状态")
    private String currentStatus;





    @Getter
    public enum CURRENT_TYPE {
        //缺少已退款
        NO_PAY("已报名,待下单", "NO_PAY"),
        TIME_OUT("已超时", "TIME_OUT"),
        CANCELLED("已取消", "CANCELLED"),
        REFUND("已退款", "REFUND"),
        WAITING_COMMENT("待点评", "WAITING_COMMENT"),
        WAITING_REVIEW("待审核", "WAITING_REVIEW"),
        REVIEW_APPROVED("审核通过", "REVIEW_APPROVED"),
        REVIEW_REJECT("审核驳回", "REVIEW_REJECT");

        private final String desc;
        private final String value;

        CURRENT_TYPE(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        // 通过value获取枚举实例
        public static CURRENT_TYPE fromValue(String value) {
            for (CURRENT_TYPE type : values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("未知的状态类型: " + value);
        }
    }


    /**
     * 类型：1-支付  3-提现
     */
    @TableField("payment_type")
    @ApiModelProperty("支付类型：WECHAT POINTS")
    private String paymentType;

    @Getter
    public enum PAYMENT_TYPE {
        WECHAT("微信", "WECHAT"),
        POINTS("积分", "POINTS");

        private final String desc;
        private final String value;

        PAYMENT_TYPE(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        // 通过value获取枚举实例
        public static PAYMENT_TYPE fromValue(String value) {
            for (PAYMENT_TYPE type : values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("未知的状态类型: " + value);
        }
    }
}
